local status_ok, which_key = pcall(require, "which-key")
if not status_ok then
  return
end

local setup = {}

local opts = {
  mode = "n", -- NORMAL mode
  prefix = "<leader>",
  buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  silent = true, -- use `silent` when creating keymaps
  noremap = true, -- use `noremap` when creating keymaps
  nowait = true, -- use `nowait` when creating keymaps
}

which_key.add(
{
  --{ "<leader>f", group = "file" }, -- group
  --{ "<leader>ff", "<cmd>Telescope find_files<cr>", desc = "Find File", mode = "n" },
--  { "<leader>fb", function() print("hello") end, desc = "Foobar" },
--  { "<leader>fn", desc = "New File" },

  { "<leader>F", "<cmd>Telescope live_grep<cr>", desc = "Find Text" },
  { "<leader>e", "<cmd>NvimTreeToggle<cr>", desc = "Explorer" },

  { "<leader>P", "<cmd>lua require('telescope').extensions.projects.projects()<cr>", desc = "Projects" },
  { "<leader>S", "<cmd>Telescope tags<cr>", desc = "Find Tags" },
  { "<leader>U", "<cmd>UndotreeToggle<cr>", desc = "Undo Tree Toggle" },
  { "<leader>y", "<cmd>:YRShow<cr>", desc = "YRShow" },

  { "<leader>b", "<cmd>lua require('telescope.builtin').buffers(require('telescope.themes').get_dropdown{previewer = false})<cr>", desc = "Buffers" },

  { "<leader>f", "<cmd>lua require('telescope.builtin').find_files(require('telescope.themes').get_dropdown{previewer = false})<cr>", desc = "Find files"},

  { "<leader>C", group = "Coc" },
  { "<leader>Cc", "<cmd>Telescope coc<cr>", desc = "Find Coc" },
  { "<leader>Cd", "<cmd>Telescope coc definitions<cr>", desc = "Coc Definitions" },
  { "<leader>Cr", "<cmd>Telescope coc references<cr>", desc = "Coc References" },
  { "<leader>Cs", "<cmd>Telescope coc workspace_symbols<cr>", desc = "Coc workspace_symbols" },

  { "<leader>g", group = "Git" },
  { "<leader>go", "<cmd>Telescope git_status<cr>", desc = "Open changed file" },
  { "<leader>gb", "<cmd>Telescope git_branches<cr>", desc = "Checkout branch" },
  { "<leader>gc", "<cmd>Telescope git_commits<cr>", desc = "Checkout commit" },

  { "<leader>s", group = "Search" },
  { "<leader>sb", "<cmd>Telescope git_branches<cr>", desc = "Checkout branch" },
  { "<leader>sc", "<cmd>Telescope colorscheme<cr>", desc = "Colorscheme" },
  { "<leader>sh", "<cmd>Telescope help_tags<cr>", desc = "Find Help" },
  { "<leader>sM", "<cmd>Telescope man_pages<cr>", desc = "Man Pages" },
  { "<leader>sr", "<cmd>Telescope oldfiles<cr>", desc = "Open Recent File" },
  { "<leader>sR", "<cmd>Telescope registers<cr>", desc = "Registers" },
  { "<leader>sk", "<cmd>Telescope keymaps<cr>", desc = "Keymaps" },
  { "<leader>sC", "<cmd>Telescope commands<cr>", desc = "Commands" },

  {
    -- Nested mappings are allowed and can be added in any order
    -- Most attributes can be inherited or overridden on any level
    -- There's no limit to the depth of nesting
    mode = { "n", "v" }, -- NORMAL and VISUAL mode
    { "<leader>q", "<cmd>q<cr>", desc = "Quit" }, -- no need to specify mode since it's inherited
    { "<leader>w", "<cmd>w<cr>", desc = "Write" },
  }
}
)
